//
//  JOSettingController.m
//  网易彩票
//
//  Created by song on 15/2/9.
//  Copyright (c) 2015年 song. All rights reserved.
//

#import "JOSettingController.h"
#import "JOSettingItem.h"
#import "JOSettingSwitchItem.h"
#import "JOSettingArrowItem.h"
#import  "JOSettingGroup.h"
#import "JOSettingOneController.h"
#import "JOSettingTwoController.h"
#import "JOSettingCell.h"
#import "JOProductViewController.h"

@interface JOSettingController ()

@property(nonatomic , strong) NSMutableArray *data;

@end

@implementation JOSettingController


-(instancetype)init
{

    return [super initWithStyle:UITableViewStyleGrouped];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title =@"设置";

}

-(NSArray *) data
{
    if(_data ==nil)
    {
//        _data =[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Settings.plist" ofType:nil]] ;
        _data = [NSMutableArray array];
        
        JOSettingGroup *group0 =[[JOSettingGroup alloc] init];
        
        JOSettingItem *item0 = [JOSettingArrowItem itemWithIcon:@"handShake" title:@"摇一摇" destVcClass:[JOSettingOneController class]];
        
        JOSettingItem *item1 = [JOSettingItem itemWithIcon:@"MoreAbout" title:@"更多" ];
        
        JOSettingItem *item2 = [JOSettingArrowItem itemWithIcon:@"handShake" title:@"产品相关" destVcClass:[JOProductViewController class]];
        
        item1.option=^(){
            NSLog(@"hello word!");
        };
        group0.items = @[item0 , item1 ,item2];
        
        
        
        JOSettingGroup  *group1 = [[JOSettingGroup alloc] init];
        group1.items = @[item0 , item1,item2];
        [_data addObject:group0];
        [_data addObject:group1];
    }
    return _data;
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    
    return self.data.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    
    return [[self.data[section] items] count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *ID=@"setting";
    
    JOSettingCell *cell = [JOSettingCell cellWithTableView:tableView];
    
    JOSettingGroup *group = self.data[indexPath.section];
    
    JOSettingItem *item = group.items[indexPath.row];
    
    cell.item = item;
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    JOSettingGroup *group = self.data[indexPath.section];
    
    JOSettingItem *item = group.items[indexPath.row];
    
    if(item.option)
    {
        item.option();
    }
    
    if([item isKindOfClass:[JOSettingArrowItem class]])
    {
        JOSettingArrowItem *arrowItem =  (JOSettingArrowItem *) item;
        Class c = arrowItem.destVcClass;
        UIViewController  *vc =[[c alloc]init];
        vc.title = arrowItem.title;
        [self.navigationController pushViewController:vc animated:YES];
    }
    

    
}


@end
